package com.fhz.fengmvvm.test;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

/**
 * 时间:11/9/21
 *
 * @author msfeng
 * 简述: TODO
 */
public class MyViewModelFactory implements ViewModelProvider.Factory {

    private int index;

    public MyViewModelFactory(int index) {
        this.index = index;
    }

    /**
     * 手动创建一个viewModel
     * @param modelClass
     * @param <T>
     * @return
     */
    @NonNull
    @Override
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        return (T) new MyViewModel(index);
    }
}
